package com.glls.order.exception;

import com.alibaba.csp.sentinel.slots.block.degrade.DegradeException;
import com.alibaba.csp.sentinel.slots.block.flow.FlowException;
import com.glls.common.R;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * TODO
 *
 * @author junyang
 * @version 1.0.0
 * @date 2025/2/27 9:58
 */
@ControllerAdvice
@ResponseBody
public class GlobalExceptionHandler {

    @ExceptionHandler(value = FlowException.class)
    public R handlerFlowException(FlowException ex){
        return R.error().code(500).message("当前系统访问人数过多，请稍后再试");
    }


    @ExceptionHandler(value = DegradeException.class)
    public R handlerDegreeException(DegradeException ex){
        return R.error().code(500).message("系统开小差，请稍后再试");
    }


    @ExceptionHandler(value = ArithmeticException.class)
    public R handlerArithmeticException(Exception ex){
        return R.error().code(500).message("数学运算异常，请检查");
    }

    @ExceptionHandler(value = Exception.class)
    public R handlerException(Exception ex){
        return R.error().code(500).message("未知异常，请联系统");
    }

}
